import axios from 'axios';
import baseURL from './url';

const axiosInstance = axios.create({
    baseURL: baseURL,
    headers: {
        'Content-Type': 'application/json; charset=UTF-8;',
        // 'Content-Disposition':'attachment',
        // 'Accept-Ranges': 'bytes',
        // 'Content-Transfer-Encoding': 'binary'
    },
    withCredentials: true,
    timeout: 50000
});


axiosInstance.interceptors.request.use(
    config => {
        if (config.method == 'post') {
            config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        }

        // token 放到Header中
        if(sessionStorage.getItem('access_token')){
            config.headers['token'] = sessionStorage.getItem('access_token');
        }

        return config;
    }, error => {
        return Promise.reject(error);
    });


export default axiosInstance;
